﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Yxinmt.SmarterStreaming
{
    public class SmartPublisherConfig
    {
        /// <summary>
        /// 视频采集设置
        /// </summary>
        public VideoCollectionSetting VideoCollectionSetting { get; set; }

        /// <summary>
        /// 视频码率控制
        /// </summary>
        public VideoRateControl VideoRateControl { get; set; }

        /// <summary>
        /// 音频采集设置
        /// </summary>
        public AudioCollectionSetting AudioCollectionSetting { get; set; }

        /// <summary>
        /// RTMP推送
        /// </summary>
        public RtmpPublisher RtmpPublisher { get; set; }

        /// <summary>
        /// 本地录像
        /// </summary>
        public LocalRecorder LocalRecorder { get; set; }

        public SmartPublisherConfig()
        {
            VideoCollectionSetting = new VideoCollectionSetting();
            VideoRateControl = new VideoRateControl();
            AudioCollectionSetting = new AudioCollectionSetting();
            RtmpPublisher = new RtmpPublisher();
            LocalRecorder = new LocalRecorder();
        }

        public bool IsLog { get; set; }
    }

    /// <summary>
    /// 本地录像,注意:录像目录和文件名前缀必须是英文
    /// </summary>
    public class LocalRecorder
    {
        /// <summary>
        /// 录像目录
        /// </summary>
        public string RecordDir { get; set; }
        /// <summary>
        /// 录像文件名前缀(必须是纯英文)
        /// </summary>
        public string FileNamePrefix { get; set; }
        /// <summary>
        /// 单个文件大小(单位:MB, 范围:5-800MB)
        /// </summary>
        public int SingleRecordMaxFileSize { get; set; }
        /// <summary>
        /// 文件名增加日期
        /// </summary>
        public bool IsAppendDate { get; set; }
        /// <summary>
        /// 文件名增加时间
        /// </summary>
        public bool IsAppendTime { get; set; }
    }

    /// <summary>
    /// RTMP推送
    /// </summary>
    public class RtmpPublisher
    {
        /// <summary>
        /// RTMP推送地址
        /// </summary>
        public string PublishUrl { get; set; }
    }

    /// <summary>
    /// 音频采集设置(扬声器和麦克风全选可以混音输出)
    /// </summary>
    public class AudioCollectionSetting
    {
        /// <summary>
        /// 采集扬声器
        /// </summary>
        public bool IsAuidoSpeakerInput { get; set; }
        /// <summary>
        /// 采集麦克风
        /// </summary>
        public bool IsAuidoMicInput { get; set; }
        /// <summary>
        /// 音频设备
        /// </summary>
        public string AudioDevice { get; set; }
        /// <summary>
        /// 静音
        /// </summary>
        public bool IsMute { get; set; }
        /// <summary>
        /// 回音消除
        /// </summary>
        public bool IsEchoCancel { get; set; }
        /// <summary>
        /// 回音时延(毫秒)
        /// </summary>
        public int EchoDelay { get; set; }
        /// <summary>
        /// 使用speex编码
        /// </summary>
        public bool IsSpeexEncoder { get; set; }
        /// <summary>
        /// Speex编码质量(0-10)
        /// </summary>
        public int SpeexQuality { get; set; }
        /// <summary>
        /// 噪音抑制
        /// </summary>
        public bool IsNoiseSuppression { get; set; }
        /// <summary>
        /// 自动增益控制
        /// </summary>
        public bool IsAgc { get; set; }
        /// <summary>
        /// 端点检测(VAD)
        /// </summary>
        public bool IsVad { get; set; }
    }

    /// <summary>
    /// 视频码率控制(注意：要么使用平均码率，要么使用视频质量,不可以同时使用), 为达到最佳效果,可以自己调节
    /// </summary>
    public class VideoRateControl
    {
        /// <summary>
        /// 使用平均码率
        /// </summary>
        public bool IsVideoBitRate { get; set; }
        /// <summary>
        /// 平均码率(kbps)
        /// </summary>
        public int AvgBitRate { get; set; }
        /// <summary>
        /// 视频质量(0-20)
        /// </summary>
        public int VideoQuality { get; set; }
        /// <summary>
        /// 最大码率(kbps)
        /// </summary>
        public int VideoMaxBitRate { get; set; }
        /// <summary>
        /// 关键帧间隔(比如每隔10帧一个关键帧)
        /// </summary>
        public int KeyFrame { get; set; }
        /// <summary>
        /// H264 Profile
        /// </summary>
        public EnumH264ProfileType H264Profile { get; set; }
        /// <summary>
        /// 编码速度(1-6),值越小越快
        /// </summary>
        public int VideoEncodeSpeed { get; set; }
        /// <summary>
        /// 相同图像检测
        /// </summary>
        public bool IsVideoSameImage { get; set; }
        /// <summary>
        /// 最大帧间隔(毫秒)
        /// </summary>
        public int MaxVideoFrameInterval { get; set; }
        /// <summary>
        /// 最大关键帧间隔(毫秒)
        /// </summary>
        public int MaxKeyFrameInterval { get; set; }
    }

    public enum EnumH264ProfileType
    {
        Baseline,
        Main,
        High
    }

    /// <summary>
    /// 视频采集设置
    /// </summary>
    public class VideoCollectionSetting
    {
        /// <summary>
        /// 采集桌面
        /// </summary>
        public bool IsDesktopInput { get; set; }
        /// <summary>
        /// 采集帧率(帧/秒)
        /// </summary>
        public int CaptureFps { get; set; }
        /// <summary>
        /// 屏幕裁剪
        /// </summary>
        public ScreenClip ScreenClip { get; set; }

        public VideoCollectionSetting()
        {
            ScreenClip = new ScreenClip();
            IsDesktopInput = true;
        }
    }

    /// <summary>
    /// 屏幕裁剪(宽须是16倍数, 高是8倍数)
    /// </summary>
    public class ScreenClip
    {
        public int Left { get; set; }
        public int Top { get; set; }
        public int Width { get; set; }
        public int Height { get; set; }
    }
}
